<template>
    <div>
        <el-table :data="specslist" border style="width: 100%">
            <el-table-column prop="id" label="规格编号" width="180">
            </el-table-column>
            <el-table-column prop="specsname" label="规格名称" width="180">
            </el-table-column>
            <el-table-column prop="attrs" label="规格属性">
                <template slot-scope="item">
                    <div>
                        <el-button  type="info" plain size="small"
                        v-for="attr in item.row.attrs" :key="attr">{{attr}}</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="状态">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" plain size="small">{{ item.status == 1 ? '启用' : '禁用' }}</el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="status" label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" icon="el-icon-edit" @click="edit(item.row.id)" circle></el-button>
                        <el-button type="danger" icon="el-icon-delete" @click="del(item.row.id)" circle></el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination :page-size="getSize" background layout="prev, pager, next" :total="count" @current-change="changePage"
        >
        </el-pagination>
    </div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
import { specsDelete } from '../../request/api'
export default {
    data() {
        return {
            
        }
    },
    methods: {
       
        edit(id){
            this.$emit('edit',id)
        },
        ...mapActions({
            getSpecs: 'specs/getSpecsListAction',
            getCount:'specs/getCountAction',
            changePageInfo:'sepcs/changePageAction'
        }),
         // 切换页码事件
         changePage(n){
            console.log(n);
            this.changePageInfo(n)
        },
        // 删除事件
        del(id) {
            this.$confirm('你确定要删除吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                specsDelete({ id }).then(res => {
                    if(res.code==200){
                        this.$message.success(res.msg)
                        // 页面一加载就加载数据
                        this.getSpecs()
                        this.getCount()
                    }else{
                        this.$message.error(res.msg)
                    }
                })
            }).catch(()=>{
                this.$message({
                    type:'info',
                    message:'已取消删除'
                })
            })

        }

    },
    mounted() {
        // console.log(this.specslist);
        // 页面已加载就调用列表及总数
        this.getSpecs()
        this.getCount()
    },
    watch: {},
    computed: {
        ...mapGetters({
            specslist: 'specs/getSpecsList',      
            getSize:'specs/getSize',
            count:'specs/getCount'
        })
    },
    filters: {},
    components: {}
}
</script>
<style scoped></style>